<template>
	<view>
		<cu-custom :bgcolor="'#fff'" />
		<view>
			<view class="tip p-4 mb-2">
				<view class="text-danger font-md">
					注意：以下信息必修全部填写</view>
			</view>
			<!-- <scroll-view scroll-y="true" :style="'height:'+scorllHeight+ 'px;'" @scrolltolower="loadMore"> -->
			<view class="shop-list" v-if="shopList && shopList.length > 0">
				<view class="list-box pt-3 pb-3 pl-4 pr-4 mb-2" v-for="(item, index) in shopList" :key="index">
					<view class="list">
						<view class="pt-2 pb-2 d-flex flex-column">
							<view class="d-flex flex-row a-center j-sb mb-2">
								<view class="span-20 ">
									<text class="mb-1 d-block">标题</text>
									<input class="uni-input border rounded" v-model="item.title"
										placeholder="请输入标题" />
								</view>
							
							</view>
							<view class="d-flex flex-row a-center j-sb span-20 mb-2">
								<view class="mb-1 span-20 ">
									<text class="mb-1 d-block">优惠券金额:</text>
									<uni-data-select v-model="item.money" :localdata="xqMoneyList" @change="changeXqMoney($event)"
										placeholder="请选择红包金额"></uni-data-select>
								</view>

							</view>
							<view class="d-flex flex-row a-center j-sb mb-2">
								<view class="mb-1 span-20 ">
									<text class="mb-1 d-block">优惠券金额承担:</text>
									<uni-data-select v-model="item.commitment" :localdata="otherMoneyList" @change="changeOtherMoney($event)"
										placeholder="请选择优惠券金额承担"></uni-data-select>
								</view>
							</view>
							<view class="d-flex flex-row a-center j-sb mb-2">
								<view class="span-20 ">
									<text class="mb-1 d-block">使用条件:</text>
									<uni-data-select v-model="item.ava" :localdata="filterMoneyList"
										placeholder="请选择使用条件"></uni-data-select>
								</view>

							</view>
							<view class="d-flex flex-row a-center j-sb mb-2">
								<view class="span-20 ">
									<text class="mb-1 d-block">使用有效期:</text>
									<uni-datetime-picker v-model="item.datetimerange" type="datetimerange" start="" end=""
										rangeSeparator="-" start-placeholder="开始时间" end-placeholder="结束时间" />
								</view>
							
							</view>
							
							<view class="d-flex flex-row a-center j-sb mb-2">
								<view class="span-20 ">
									<text class="mb-1 d-block">是否在店铺领取:</text>
									<uni-data-checkbox v-model="item.is_send_in_supplier" :localdata="sexs" />
								</view>
							
							</view>
							<view class="d-flex flex-row a-center j-sb mb-2">
								<view class="span-20 ">
									<text class="mb-1 d-block">是否与满减同享:</text>
									<uni-data-checkbox v-model="item.is_coexist_manjian" :localdata="coexist" />
								</view>
							
							</view>
						</view>
					</view>
				</view>

			</view>
			<view class="button-box p-2">
				<button class="main-bg-color text-white font-md" @click="submit">提交</button>
			</view>
			<!-- <view class="d-flex a-center j-center text-light-muted font-md py-3">{{loadtext}}</view> -->
			<!-- </scroll-view> -->

		</view>
	</view>
</template>

<script>
	import title from "@/components/common/title.vue"
	import divider from "@/components/common/divider.vue"
	import cuCustom from '@/components/common/custom.vue'
	import interceptor from "@/utils/request.js"
	export default {
		components: {
			title,
			divider,
			cuCustom
		},
		data() {
			return {
				value: 0,
				scorllHeight: 500,
				shopList: [{
					title:"",
					money: "",
					commitment: "",
					ava: "",
					datetimerange:[],
					start_time: "",
					end_time: "",
					is_send_in_supplier: "0",
					is_coexist_manjian: "0"
				}],
				loadtext: "上拉加载更多",
				xqMoneyList: [],
				otherMoneyList: [],
				filterMoneyList: [],
				sexs: [{
					text: '否',
					value: '0'
				}, {
					text: '是',
					value: '1'
				}],
				coexist:[{
					text: '否',
					value: '0'
				}, {
					text: '是',
					value: '1'
				}],
			}
		},
		onLoad() {
			// uni.getSystemInfo({
			// 	success: (res => {
			// 		this.scorllHeight = res.windowHeight - uni.upx2px(500)
			// 	})
			// })
			this.getXqMoney()
		},
		onShow() {

		},
		methods: {
			// 上拉加载更多
			loadMore() {
				if (this.loadtext !== '上拉加载更多') return
				this.loadtext = "加载中..."
				setTimeout(() => {
					this.shopList = [...this.shopList, ...this.addlist]
					// 回复状态
					this.loadtext = "上拉加载更多"
				}, 2000)

			},
			// 获取满金额
			getXqMoney() {
				interceptor.get('/supplier_applet_api.php?act=selFirst', {
					type: 3
				}).then((res) => {
					res.info.map((item) => {
						item.value = item.val
					})
					this.xqMoneyList =res.info
				})
			},
			changeXqMoney(e) {
				this.otherMoneyApi(e)
			},
			// 第三方查询接口
			otherMoneyApi(id) {
				interceptor.get('/supplier_applet_api.php?act=selSecond', {
					type: 3,
					money: id
				}).then((res) => {
					res.info.map((item) => {
						item.value = item.val
					})
					this.otherMoneyList = res.info
				})
			},
			
			changeOtherMoney(e) {
				this.getFilterAPi()
			},
			// 查询使用条件接口
			getFilterAPi(money, commitment) {
				interceptor.get('/supplier_applet_api.php?act=selThird', {
					type: 3,
					money: money ? money : this.shopList[0].money,
					con: commitment ? commitment : this.shopList[0].commitment
				}).then((res) => {
					res.info.map((item) => {
						item.value = item.val
					})
					this.filterMoneyList = res.info
				})
			},
			
			submit() {
				// let params = Object.assign({},{supplier_id: uni.getStorageSync('supplier_id')},this.shopList[0])
				this.shopList[0].start_time = this.shopList[0].datetimerange[0]
				this.shopList[0].end_time = this.shopList[0].datetimerange[1]
				let params = this.shopList[0]
				params.supplier_id = uni.getStorageSync('supplier_id')
				interceptor.get('/supplier_applet_api.php?act=couponAdd', params).then((res) => {
					if (res.status === 1) {
						uni.showToast({
							title: res.msg,
							icon: "none",
							success() {
								uni.navigateBack()
							}
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.search-box {
		width: 100%;
		height: 160upx;
		background: #fff;

		box-sizing: border-box;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;

		.input {
			width: 90%;
			border-radius: 20px;
			overflow: hidden;
			border: 1px solid #BBBBBB;
			position: relative;

			.icon-sousuo {
				position: absolute;
				left: 35upx;
				top: 10upx;
			}

			.search {
				position: absolute;
				right: 40upx;
				top: 8upx;
			}
		}
	}

	.shop-list {
		background: #EBECED;
		height: auto;
		padding: 32rpx;
		box-sizing: border-box;

		.list-box {
			background: #FFFFFF;
			border-radius: 20rpx;
			height: auto;

			.list {
				height: auto;
				border-bottom: 1px dashed #dcdcdc;
			}

			.list-btn {}
		}

	}

	::v-deep .uni-select--mask {
		display: none;
	}
</style>